<template>
	<view class="layout">
		<view class="layout-header">
			<view
				class="layout-header-title layout-common-title"
				:style="{
					backgroundImage: 'url(https://dyfxmp-pre.lianlianlvyou.com/avatar/original/LL_IMAGE_64fa60108e2f461abddbb818d61a9599.png)'
				}"
			>
				<image src="@/static/tandian/icon_tjsq_shopinfo.png" />
				<text>店铺信息</text>
			</view>

			<view class="layout-header-main">
				<view :key="index" v-for="(item, index) in productList" class="layout-header-main-item">
					<view class="layout-header-main-item-left">
						{{ item.label }}
					</view>

					<view class="layout-header-main-item-right">
						{{ tandianProductDetail[item.type] }}
					</view>
				</view>
			</view>
		</view>

		<view class="layout-main">
			<view class="layout-main-item">
				<view class="layout-main-item-title layout-common-title">
					<image src="@/static/tandian/icon_xqy_promote.png" />
					<text>推广信息</text>
				</view>

				<view class="layout-main-item-content">
					<block :key="index" v-for="(item, index) in promoteList">
						<view v-if="item.isShow" class="layout-main-item-content-item">
							<view class="layout-main-item-content-item-left">
								{{ item.label }}
							</view>

							<view class="layout-main-item-content-item-right">
								<image v-if="item.tips" class="layout-main-item-content-item-right-tips weights" :src="item.tips" />
								<block v-if="item.selfClick">
									<input
										:type="item.icon ? 'text' : 'number'"
										v-model="singleChannelInfo.nickName"
										:disabled="item.isSelect || isDisabled"
										:placeholder="item.placeholder"
										placeholder-class="placeholder"
										@click="showDyAccount(item, index)"
										:maxlength="item.maxLength ? item.maxLength : -1"
									/>
								</block>
								<block v-else>
									<input
										:type="item.icon ? 'text' : 'number'"
										v-model="singleChannelInfo[item.type]"
										:disabled="item.isSelect || isDisabled"
										:placeholder="item.placeholder"
										placeholder-class="placeholder"
										@click="changeSelectValue(item, index)"
										:maxlength="item.maxLength ? item.maxLength : -1"
									/>
								</block>
								<image v-if="item.icon" class="layout-main-item-content-item-right-icon" :src="item.icon" />
							</view>
						</view>
					</block>

					<!-- <view class="layout-main-item-content-addItem">
						<view>
							<image src="@/static/tandian/icon_sqtd_zj.png " />
							<text>新增渠道</text>
						</view>
					</view> -->
				</view>
			</view>

			<view class="layout-main-item">
				<view class="layout-main-item-title layout-common-title">
					<image src="@/static/tandian/icon_xqy_application.png" />
					<text>申请信息</text>
				</view>

				<view class="layout-main-item-content">
					<view class="layout-main-item-content-item">
						<view class="layout-main-item-content-item-left">探店模式</view>
						<view class="layout-main-item-content-item-right">
							<input
								type="text"
								disabled="true"
								v-model="applicationParams.seekTypeValue"
								placeholder="请选择探店模式"
								placeholder-class="placeholder"
								@click="openShopModeList"
							/>
							<image :src="iconDown" v-if="isGroupTanDian === 2"/>
						</view>
					</view>

					<view class="layout-main-item-content-item">
						<view class="layout-main-item-content-item-left">佣金模式</view>
						<view class="layout-main-item-content-item-right">
							<input
								type="text"
								disabled
								v-model="applicationParams.commissionModel"
								placeholder="请选择佣金模式"
								placeholder-class="placeholder"
								@click="openCommissionModel"
							/>
							<image :src="iconDown" />
						</view>
					</view>

					<view class="layout-main-item-content-item">
						<view class="layout-main-item-content-item-left">探店时间</view>

						<view class="layout-main-item-content-item-right">
							<input
								type="text"
								disabled
								v-model="applicationParams.exploreTimeValue"
								placeholder="请选择探店时间"
								placeholder-class="placeholder"
								@click="newChangeSelectValue('exploreTime', 'exploreTimeValue', '请选择探店时间')"
							/>
							<image :src="iconDown" v-if="isGroupTanDian !== 1" />
						</view>
					</view>
					<view class="layout-main-item-content-item">
						<view class="layout-main-item-content-item-left">探店人数</view>

						<view class="layout-main-item-content-item-right">
							<input
								type="number"
								:disabled="isCloudClip || isDisabled"
								v-model="applicationParams.explorePeople"
								placeholder="请输入探店人数"
								placeholder-class="placeholder"
								:maxlength="2"
							/>
						</view>
					</view>
					<view class="layout-main-item-content-item" v-if="isGroupTanDian !== 1 && !isCloudClip">
						<view class="layout-main-item-content-item-left">探店门店</view>

						<view class="layout-main-item-content-item-right">
							<input
								type="text"
								disabled
								placeholder="请选择门店"
								placeholder-class="placeholder"
								v-model="applicationParams.exploreStore"
								@click="openTandianStore()"
							/>
							<image :src="iconDown" v-if="isGroupTanDian !== 1" />
						</view>
					</view>

					<view class="layout-main-item-content-item">
						<view class="layout-main-item-content-item-left">预计发刊</view>

						<view class="layout-main-item-content-item-right">
							<input
								type="text"
								disabled
								placeholder="请选择预计发刊时间"
								placeholder-class="placeholder"
								v-model="applicationParams.publishTimeValue"
								@click="newChangeSelectValue('publishTime', 'publishTimeValue', '请选择预计发刊时间')"
							/>
							<image :src="iconDown" />
						</view>
					</view>

					<view class="layout-main-item-content-item" v-if="!isCloudClip && isExplorePrice">
						<view class="layout-main-item-content-item-left">您的报价</view>

						<view class="layout-main-item-content-item-right">
							<input
								type="digit"
								placeholder="请输入您的报价"
								placeholder-class="placeholder"
								:disabled="isDisabled"
								v-model="applicationParams.explorePrice"
								@blur="inputExplorePriceBlur"
							/>
						</view>
					</view>
				</view>
			</view>

			<!-- <view class="layout-main-item">
				<view class="layout-main-item-content protocol">
					<view class="protocol-left">
						<view>提供探店素材</view>
						<view>探店完成后，提供素材有机会获得我们更多福利呦～</view>
					</view>

					<view class="protocol-right">
						<image @click="changeIsNeedUpload" :src="needIconObject[applicationParams.isNeedUpload ? 'active' : 'default']" />
					</view>
				</view>
			</view> -->
		</view>

		<view class="layout-footer">
			<button
				@longpress.prevent.stop
				:disabled="isLoading"
				:loading="isLoading"
				:class="{ active: isLoading }"
				@click.prevent.stop="userRegister"
			>
				提交
			</button>
		</view>

		<Subscription :isPopup="isSubscription" />

		<BottomActionSheet
			v-model="isPopup"
			:title="popupTitle"
			:list="bottomActionSheetList"
			:otherParams="popupOtherParams"
			:activeValue="bottomActionSheetActiveList"
			@changeBottomActionSheet="changeBottomActionSheet"
		/>

		<PopupCommissionModel
			v-model="isPopupCommission"
			:title="commissionTitle"
			:list="bottomActionSheetList"
			:otherParams="popupOtherParams"
			:activeValue="bottomActionSheetActiveList"
			@changeBottomActionSheet="changeBottomActionSheet"
		/>

		<chooseDy
			v-model="isShowMoreAccount"
			:updateListFn="chooseAccItem"
			:selectAccount.sync="getAccountItem"
			:listData="getMoreAccount"
			@clickSure="clickSureFn"
		></chooseDy>
	</view>
</template>

<script>
import { mapGetters } from 'vuex';
import { WECHAT_TEMPLACTE_ID } from '@/config/base';
import { isTandian, getEveryDay } from './components/filterDate';
import { defaultImageUrl, isSubscribeNotifications } from '@/utils';
import { getChannelInfo, saveSeekApply, getCheckTypeEnd, getTanDianModuel } from '@/api/tandian';
import { getListChannelType, getAreaCode, getListAccountType } from '@/api/common';
import { dyAccountList } from '@/api/third';
import Subscription from './components/Subscription';
import BottomActionSheet from '@/components/bottomActionSheet';
import PopupCommissionModel from '@/components/popupCommissionModel';
import chooseDy from '@/components/chooseDy/chooseDy';

const iconDown = require('@/static/tandian/icon_sqtd_right.png');
const iconTips = require('@/static/tandian/icon_cargo_lv.png');

const headerBgImage = Object.freeze(`${defaultImageUrl}image/img_sqtd_bg.png`);
const needIconObject = Object.freeze({
	default: require('@/static/tandian/icon_xqy_default.png'),
	active: require('@/static/tandian/icon_xqy_selected.png')
});

const productList = Object.freeze([
	{
		type: 'subTitle',
		label: '产品名称'
	},
	// {
	// 	type: 'commissionModel',
	// 	label: '佣金模式'
	// },
	{
		type: 'content',
		label: '探店要求'
	}
]);
const promoteList = [
	{
		label: '推广平台',
		type: 'channelShowValue',
		icon: iconDown,
		isSelect: true,
		activeValue: 'channelType',
		placeholder: '请选择推广平台',
		isShow: true
	},
	{
		label: '抖音账户',
		type: 'dyAccountShowValue',
		icon: iconDown,
		isSelect: true,
		activeValue: 'dyAccountType',
		placeholder: '请选择抖音账户',
		selfClick: true,
		isShow: false
	},

	{
		label: '账户ID',
		icon: true,
		type: 'channelAccount',
		placeholder: '请填写账户ID',
		isShow: true
	},
	{
		label: '账户类别',
		type: 'accountShowValue',
		icon: iconDown,
		isSelect: true,
		original: '',
		activeValue: 'accountType',
		placeholder: '请选择账号类别',
		isShow: true
	},
	{
		label: '平台粉丝',
		type: 'channelFens',
		placeholder: '请填写粉丝数量',
		isShow: true
	},
	{
		label: '所在位置',
		type: 'locationShowValue',
		icon: iconDown,
		isSelect: true,
		activeValue: 'location',
		placeholder: '请选择所在位置',
		isShow: true
	},
	{
		label: '手机号码',
		type: 'mobile',
		placeholder: '请填写手机号码',
		maxLength: 11,
		isShow: true
	},
	{
		label: '带货等级',
		tips: iconTips,
		type: 'cargoLevel',
		placeholder: '请填写带货等级',
		maxLength: 3,
		isShow: true
	},
	{
		label: '带货分',
		type: 'cargoPoints',
		placeholder: '请填写带货分数',
		maxLength: 10,
		isShow: true
	}
];
const applicationList = [
	{
		type: 'seekType',
		placeholder: '请选择探店模式'
	},
	{
		type: 'commissionModel',
		placeholder: '请选择佣金模式'
	},
	{
		type: 'exploreTimeValue',
		placeholder: '请选择探店时间'
	},
	{
		type: 'explorePeople',
		placeholder: '请输入探店人数'
	},
	{
		type: 'exploreStore',
		placeholder: '请选择门店'
	},
	{
		type: 'publishTimeValue',
		placeholder: '请选择预计发刊时间'
	},
	{
		type: 'explorePrice',
		placeholder: '请输入您的报价'
	}
];
export default {
	name: 'applyTandian',

	data() {
		return {
			iconDown,
			promoteList,
			productList,
			needIconObject,
			isLoading: false,

			headerBgImage,

			singleChannelInfo: {
				mobile: '',
				channelFens: '',
				channelAccount: ''
			},

			isFull: false,
			isPopup: false,
			popupTitle: '',
			isSubscription: false,
			popupOtherParams: {},
			bottomActionSheetList: [],
			bottomActionSheetActiveList: [],

			isPopupCommission: false,

			applicationParams: {
				seekType: [],
				seekTypeValue: '',

				exploreTime: [],
				exploreTimeValue: '',

				explorePeople: '',
				exploreStore: '',

				publishTime: [],
				publishTimeValue: '',

				explorePrice: '',

				isNeedUpload: 0,

				commissionModel: '',
				commissionModelValue: []
			},
			getMoreAccount: [],
			isShowMoreAccount: false, // 是否展示更多账号选择
			getAccountItem: {}, // 多账号选择的账号

			shopModeList: [],
			commissionTitle: ''
		};
	},

	watch: {
		'applicationParams.commissionModelValue': {
			handler(params) {
				this.$set(this.applicationParams, 'explorePrice', '');
			}
		},

		promoteList: {
			handler(params) {
				this.$set(this.promoteList[1], 'isShow', this.getMoreAccount.length > 1);
			},
			deep: true
		},

		getAccountItem: {
			handler(params) {
				// 选择的账号
			},
			deep: true
		},
		singleChannelInfo: {
			handler(params) {
				// 选择的账号
			},
			deep: true
		},

		isCloudClip(value) {
			this.applicationParams = {
				...this.applicationParams,

				exploreTime: [],
				exploreTimeValue: '',

				explorePrice: '',
				explorePeople: value ? 1 : '',

				commissionModel: '',
				commissionModelValue: []
			};
		}
	},

	computed: {
		...mapGetters(['currentSite', 'tandianProductDetail']),

		isDisabled() {
			const { isPopup, isPopupCommission } = this;

			return isPopup || isPopupCommission;
		},

		isExplorePrice() {
			const {
				applicationParams: { commissionModelValue }
			} = this;
			const [params] = commissionModelValue || [{}];

			if (!params?.value) {
				return;
			}

			// 3 CPS
			return params?.value !== 3;
		},

		isCloudClip() {
			const {
				applicationParams: { seekType }
			} = this;
			
			return seekType[0]?.value === 2;
		},
		// 1 groupItem组件拼团 2 详情页独立探店 3 详情页拼团探店
		isGroupTanDian() {
			const {
				tandianProductDetail: { isSingle }
			} = this;
			return isSingle
		}
	},

	created() {
		const {
			tandianProductDetail: { endTime, validEndDate, bizProductId, commissionsList,applyNeedObj: { exploreTimeStr, exploreTimeScope = '' }},formatShopModelList,
			isGroupTanDian
		} = this;
		console.log(this.tandianProductDetail)
		getCheckTypeEnd({ productId: bizProductId }).then((res) => {
			res?.data && (this.isFull = true);

			this.commissionModelList = (commissionsList || []).map((item, index) => {
				let { label, commissionType } = item;

				commissionType === 1 && (label += res?.data || '');

				return {
					label,
					index,
					value: commissionType
				};
			});
		});

		getTanDianModuel({ productId: bizProductId }).then((responseParams) => {
			this.shopModeList = responseParams?.data || []; 

			let formatResult = formatShopModelList(responseParams?.data) || []
			let filterObj = null
			// 不是独立探店就设置探店模式默认值
			if(isGroupTanDian !== 2 ){
				filterObj = formatResult.filter(item=>item.label === '拼团到店')
				this.applicationParams.seekTypeValue = '拼团到店'
			}else{
				filterObj = formatResult.filter(item=>item.label === '独立到店')
				this.applicationParams.seekTypeValue = '独立到店'
			}
			this.applicationParams.seekType = filterObj
		});

		// validEndDate  表示产品使用结束时间
		// endTime   表示   探店结束时间
		this.getSelectData();
		let newEndTime = endTime + 1000 * 60 * 60 * 24 * 30;
		this.timeDataList = getEveryDay(Date.now(), newEndTime < validEndDate ? newEndTime : validEndDate);
		this.tandianTimeDatalist = getEveryDay(Date.now(), endTime);

		if(isGroupTanDian === 1){
			this.$set(this.applicationParams,'exploreTimeValue',exploreTimeStr || '')
			this.$set(this.applicationParams,'exploreTimeScope',exploreTimeScope || '')
		}
		
	},
	onShow() {
	
		// 更新多账号
		dyAccountList().then((res = {}) => {
			const { data = [] } = res;
			if (data.length > 1) {
				this.getMoreAccount = data;
			} else if (data.length === 1) {
				this.getMoreAccount = data;
				this.$nextTick(() => {
					this.$set(this.promoteList[1], 'isShow', false);
				});

				if (data[0].isDefault !== 1) {
					uni.showToast({
						mask: true,
						icon: 'none',
						title: '抖音账号不完善,即将跳转'
					});
					setTimeout(() => {
						uni.reLaunch({
							url: `/thirdManage/dyAccount`
						});
					}, 1500);
				}
			}
		});
	},
	methods: {
		openCommissionModel() {
			const {
				isCloudClip,
				commissionModelList,
				applicationParams: { commissionModelValue }
			} = this;

			uni.hideKeyboard();

			this.popupOtherParams = {
				type: 'commissionModel',
				singleType: 'application',
				activeValue: 'commissionModelValue'
			};

			this.commissionTitle = '请选择佣金模式';

			this.bottomActionSheetList = commissionModelList.filter((item) => {
				if (item.value === 1) {
					return;
				}

				if (isCloudClip) {
					return item.value === 3;
				}

				return true;
			});

			this.bottomActionSheetActiveList = commissionModelValue || [];
			this.isPopupCommission = true;
		},

		openShopModeList() {
			const {
				shopModeList,
				applicationParams: { seekType },
				formatShopModelList,
				isGroupTanDian
			} = this;

			if(isGroupTanDian !== 2){
				return
			}
			this.popupOtherParams = {
				type: 'seekTypeValue',
				singleType: 'seekType',
				activeValue: 'seekType'
			};
			this.bottomActionSheetList = formatShopModelList(shopModeList)
			
			this.commissionTitle = '请选择探店模式';
			// 3.4,3.5 产品需求 todo
			// 若独立到店发起申请，则探店模式默认选择独立到店，可以切换选择云剪辑，无法选择拼团探店
			// 参与他人拼团的用户点击“去拼团”进入申请页，探店模式默认拼团探店，探店时间为拼团探店的时间、门店地址无法修改选择；（发起拼团可以选择探店时间和门店地址）
					
			this.bottomActionSheetActiveList = seekType;
			
			this.isPopupCommission = true;
		},

		formatShopModelList(arr=[]){
			return arr.map((item) => {
	
				const { seekType, seekName } = item;

				return {
					value: seekType,
					label: seekName,
					isDisabled: this.isGroupTanDian === 2 && item.seekName === '拼团到店' ? true : false
				};
			});
		},

		inputExplorePriceBlur(e) {
			const currentValue = e.detail.value;
			let value = Number(currentValue);

			if (currentValue.replace(/\s/g, '') === '' || isNaN(value)) {
				value = '';
			}

			if (value) {
				value = value.toString();
				const index = value.indexOf('.');

				value = index !== -1 ? value.substring(0, 2 + index + 1) : value.substring(0);
				value = parseFloat(value).toFixed(2);
			}

			this.$set(this.applicationParams, 'explorePrice', value);
		},

		getSelectData() {
			Promise.all([getListAccountType(), getAreaCode(), getListChannelType(), dyAccountList()]).then((res) => {
				const [accountList, areaList, singleList, data] = res;

				const filterAccountList = (accountList?.data || []).map((item) => {
					const { desc, value } = item;

					return {
						value: Number(value),
						label: desc
					};
				});

				const filterSchannelList = (singleList?.data || []).map((item) => {
					const { desc, value } = item;
					return {
						label: desc,
						value: Number(value)
					};
				});

				const paramsObject = {
					channelType: filterSchannelList,
					accountType: filterAccountList,
					location: areaList?.data[0]?.children || []
				};
				this.getMoreAccount = data?.data || [];

				this.promoteList = this.promoteList.map((item) => {
					return {
						...item,
						list: paramsObject[item.activeValue]
					};
				});

				this.channelList = filterSchannelList;
				this.accountList = filterAccountList;
				this.locationList = areaList?.data[0]?.children || [];
				this.getChannelInfoFn().then((res) => {
					this.getChannelInformation(res);
				});
			});
		},
		getChannelInformation(obj = {}) {
			const { channelList, accountList, locationList } = this;
			const { channelType, accountType, province, city } = obj;
			const channelIndex = channelList.findIndex((item) => item.value === channelType);
			const accountIndex = accountList.findIndex((item) => item.value === accountType);

			const locationIndexComputed = locationList.findIndex((item) => item.value === province);
			const locationIndex = locationIndexComputed !== -1 ? locationIndexComputed : '';
			const subLocationIndexComputd = (locationList[locationIndex]?.children || []).findIndex((item) => item.value === city);
			const subLocationIndex = subLocationIndexComputd !== -1 ? subLocationIndexComputd : '';
			let locationShowValue = [];
			if (locationIndexComputed !== -1) {
				locationShowValue = `${locationList[locationIndex].label}-${locationList[locationIndex].children[subLocationIndex].label}`;
			}

			this.singleChannelInfo = {
				...this.singleChannelInfo,
				...obj,
				channelShowValue: channelList[channelIndex]?.label,
				channelType: [
					{
						index: channelIndex
					}
				],

				accountShowValue: accountList[accountIndex]?.label,
				accountType: [
					{
						index: accountIndex
					}
				],

				locationShowValue,
				location: [
					{
						index: locationIndex
					},
					{
						index: subLocationIndex
					}
				]
			};
		},

		getChannelInfoFn() {
			return new Promise((resolve, reject) => {
				getChannelInfo().then((res) => {
					const single = (res?.data || [])[0] || {};
					resolve(single);
				});
			});
		},

		changeSelectValue(params, index) {
			const { singleChannelInfo } = this;
			const { isSelect, list, activeValue, placeholder } = params;

			if (!isSelect) {
				return;
			}

			uni.hideKeyboard();

			this.popupTitle = placeholder;
			this.bottomActionSheetList = list;
			this.popupOtherParams = {
				index,
				...params
			};
			this.bottomActionSheetActiveList = singleChannelInfo[activeValue]
				.map((item) => {
					return item.index;
				})
				.filter((itemIndex) => itemIndex);
			this.isPopup = true;
		},

		changeBottomActionSheet(value, otherParams) {
			const { type, activeValue, singleType } = otherParams;
		
			if (['application', 'seekType'].includes(singleType)) {
				this.applicationParams = {
					...this.applicationParams,
					[activeValue]: value,
					[type]: value.map((item) => item.label).join(' ')
				};
			
				return;
			}

			const filtersValue = value.map((item) => item.label).join('-');
			this.singleChannelInfo[type] = filtersValue;
			this.singleChannelInfo = {
				...this.singleChannelInfo,
				[activeValue]: value,
				[type]: filtersValue
			};
			
		},

		userRegister() {
			const {
				isFull,

				isCloudClip,
				isExplorePrice,

				currentSite,
				singleChannelInfo,
				tandianProductDetail: { applyNeedObj:{id} ,tdStock, saleCount, ...otherParams },
				applicationParams: { exploreTimeScope,exploreTimeValue ,exploreTime, publishTime, commissionModelValue, ...otherApplicationParams },
				isGroupTanDian
			} = this;
			/**
			 * 提交校验
			 */
			let status = [
				{
					type: 'channelAccount',
					placeholder: '请填写账户ID'
				},
				{
					type: 'channelFens',
					placeholder: '请填写粉丝数量'
				},
				{
					type: 'locationShowValue',
					placeholder: '请选择所在位置'
				},
				{
					type: 'mobile',
					placeholder: '请填写手机号码'
				},
				{
					type: 'cargoLevel',
					placeholder: '请填写带货等级'
				},
				{
					type: 'cargoPoints',
					placeholder: '请填写带货分数'
				}
			].some((item) => {
				if (!singleChannelInfo[item.type] || String(singleChannelInfo[item.type]).replace(/\s/g) === '') {
					uni.showToast({
						mask: true,
						icon: 'none',
						title: item.placeholder
					});
					return true;
				}
			});

			if (status) {
				return;
			}

			const myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
			if (!myreg.test(singleChannelInfo.mobile)) {
				uni.showToast({
					mask: true,
					icon: 'none',
					title: '手机号格式不正确'
				});
				return;
			}
			const rep = /^[1-9]\d*$/;
			if (!rep.test(singleChannelInfo.cargoLevel)) {
				uni.showToast({
					mask: true,
					icon: 'none',
					title: '带货等级格式不正确'
				});
				return;
			}
			if (!rep.test(singleChannelInfo.cargoPoints)) {
				uni.showToast({
					mask: true,
					icon: 'none',
					title: '带货分格式不正确'
				});
				return;
			}
			// if (!/^[A-Za-z0-9]+$/.test(singleChannelInfo.cargoLevel) || /^[a-z]+$/i.test(singleChannelInfo.cargoLevel)) {
			// 	// 包含字母、数字   || 包含
			// 	uni.showToast({
			// 		mask: true,
			// 		icon: 'none',
			// 		title: '带货等级格式不正确'
			// 	});
			// 	return false;
			// }

			status = applicationList.some((item) => {
				const { type, placeholder } = item;

				if (isCloudClip && ['exploreStore', 'explorePrice'].includes(type)) {
					return;
				}

				if(this.isGroupTanDian === 1 && ['exploreStore'].includes(type)){
					return;
				}

				if (type === 'explorePrice') {
					if (isExplorePrice && (this.applicationParams[type] === '' || this.applicationParams[type] < 0)) {
						uni.showToast({
							mask: true,
							icon: 'none',
							title: placeholder
						});
						return true;
					}
				} else {
					if (!this.applicationParams[type]) {
						uni.showToast({
							mask: true,
							icon: 'none',
							title: placeholder
						});
						return true;
					}
				}
				// if (type === 'explorePeople' && Number(this.applicationParams[type]) > Number(tdStock - saleCount)) {
				// 	uni.showToast({
				// 		mask: true,
				// 		icon: 'none',
				// 		title: '探店人数不能超过仅剩人数'
				// 	});
				// 	return true;
				// }
			});

			if (status || (!status && isTandian(exploreTime, publishTime))) {
				return;
			}
			if (!this.applicationParams.explorePeople || !Number(this.applicationParams.explorePeople)) {
				uni.showToast({
					mask: true,
					icon: 'none',
					title: '探店人数不能为0'
				});
				return;
			}

			if (isFull && commissionModelValue.some((item) => item.value === 1)) {
				uni.showToast({
					mask: true,
					icon: 'none',
					title: '当前产品拍摄费名额已满，请选择其它佣金模式！'
				});
				return;
			}
			this.isLoading = true;
			const {
				latitude, // 门店的纬度
				longitude, // 门店的纬度
				explorePeople, // 探店人数
				explorePrice, // 探店报价
				isNeedUpload,
				exploreStore,

				seekType,
				exploreStoreAddress // 探店门店地址
			} = otherApplicationParams;

			const params = {
				channels: [
					{
						city: singleChannelInfo.location[1].value || singleChannelInfo.city,
						province: singleChannelInfo.location[0].value || singleChannelInfo.province,

						mobile: singleChannelInfo.mobile, // 手机号
						nickName: singleChannelInfo.nickName || '', // 平台账号名称
						channelAccount: singleChannelInfo.channelAccount, // 渠道账户
						channelFens: singleChannelInfo.channelFens, // 渠道粉丝
						cargoPoints: singleChannelInfo.cargoPoints,
						cargoLevel: singleChannelInfo.cargoLevel,
						channelType:
							singleChannelInfo.channelType[0]?.value || this.channelList[singleChannelInfo.channelType[0].index].value, // 推广渠道

						accountType:
							singleChannelInfo.accountType[0]?.value || this.accountList[singleChannelInfo.accountType[0].index].value // 账号类别
					}
				],

				productId: otherParams.bizProductId,
				productName: otherParams.productTitle,
				skuId: otherParams.id,
				skuName: otherParams.subTitle,
				locationId: currentSite.id,
				latitude,
				longitude,
				explorePeople,
				isNeedUpload,
				exploreStore,
				exploreStoreAddress,

				seekType: seekType[0].value,

				explorePrice: explorePrice || 0,

				exploreTime: isGroupTanDian === 1 ? `${exploreTimeValue.split(' ')[0]} 00:00:00` : `${exploreTime[0].label} 00:00:00`, // 探店时间
				exploreTimeScope: isGroupTanDian === 1 ? exploreTimeScope : `${exploreTime[1].label}`, // 探店时间范围

				publishTime: `${publishTime[0].label} 00:00:00`, // 预计发刊时间
				publishTimeScope: `${publishTime[1].label}`, // 预计发刊时间范围

				commissionType: commissionModelValue[0]?.value || '',
				groupSeekId: id || '' 
			};

			console.log(params, 'params');

			saveSeekApply(params)
				.then((res) => {
					const { data, code } = res;

					if (code !== 200) {
						return;
					}

					this.isLoading = false;

					isSubscribeNotifications().then((status) => {
						const url = `/productOrderPage/orderDetails?orderId=${data}`;

						if (status) {
							uni.redirectTo({
								url
							});
							return;
						}

						this.isSubscription = true;

						uni.requestSubscribeMessage({
							tmplIds: [WECHAT_TEMPLACTE_ID],
							complete: (res) => {
								this.isSubscription = false;

								uni.redirectTo({
									url
								});
							}
						});
					});
				})
				.catch((e) => {
					const { data } = e || {};

					data?.msg &&
						uni.showToast({
							mask: true,
							icon: 'none',
							title: data?.msg
						});

					this.isLoading = false;
				});
		},

		newChangeSelectValue(singleParams, value, popupTitle) {
			const { timeDataList, tandianTimeDatalist,isGroupTanDian } = this;
			if(isGroupTanDian === 1 && value === 'exploreTimeValue'){
				return
			}
			this.bottomActionSheetList = singleParams === 'exploreTime' ? tandianTimeDatalist : timeDataList;

			this.popupOtherParams = {
				type: value,
				singleType: 'application',
				activeValue: singleParams
			};

			uni.hideKeyboard();
			this.popupTitle = popupTitle;
			this.bottomActionSheetActiveList = (this.applicationParams[singleParams] || []).map((item) => item.index);
			this.isPopup = true;
		},

		openTandianStore(params) {
			if(this.isGroupTanDian === 1){
				return
			}
			const url = `/tandianPage/TandianStore`;

			uni.navigateTo({
				url
			});
		},

		changeExploreShopInfo(params = {}) {
			this.applicationParams = {
				...this.applicationParams,
				...params
			};
		},

		changeIsNeedUpload() {
			this.applicationParams.isNeedUpload = !this.applicationParams.isNeedUpload ? 1 : 0;
		},

		showDyAccount(item, index) {
			this.isShowMoreAccount = true;
		},
		clickSureFn() {
			const { singleChannelInfo, getAccountItem = {}, getChannelInformation } = this;

			if (Object.keys(getAccountItem).length) {
				this.getChannelInformation(getAccountItem);
			}
		}
	},

	components: {
		Subscription,
		BottomActionSheet,
		PopupCommissionModel,
		chooseDy
	}
};
</script>

<style lang="scss" scoped>
@import '@/style/common.scss';

.layout {
	@include Db_iosBottomDistance(140rpx);

	&-common-title {
		height: 104rpx;
		padding-left: 38rpx;
		display: flex;
		align-items: center;
		background-repeat: no-repeat;
		background-size: 220rpx 220rpx;
		background-position: 472rpx 8rpx;

		color: #fff;
		font-size: 32rpx;
		font-weight: bold;

		image {
			width: 48rpx;
			height: 48rpx;
			margin-right: 8rpx;
		}
	}

	&-header {
		// min-height: 366rpx;
		position: relative;

		&-main {
			overflow: hidden;
			background: #fff;
			border-radius: 24rpx;

			margin-left: 20rpx;
			width: calc(100% - 40rpx);
			padding: 0 28rpx 30rpx 28rpx;

			&-item {
				display: flex;
				font-size: 26rpx;
				margin-top: 30rpx;

				&-left {
					color: #666;
					width: 130rpx;
				}

				&-right {
					flex: 1;
					color: #333;
					font-weight: bold;
					line-height: 36rpx;
					text-overflow: -o-ellipsis-lastline;
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					line-clamp: 2;

					word-break: break-all;
					-webkit-box-orient: vertical;
				}
			}
		}

		&::before {
			content: '';
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			z-index: -1;
			height: 366rpx;
			background: linear-gradient(180deg, #5359FF 0%, rgba(151,102,255,0) 100%);
		}
	}

	&-main-item {
		padding: 0 20rpx;

		&-title {
			color: #000;
			padding-left: 18rpx;
		}

		&-content {
			overflow: hidden;
			background: #fff;
			border-radius: 24rpx;

			&-addItem {
				padding: 26rpx 28rpx 30rpx;
				border-top: 2rpx solid #fafafa;

				view {
					color: #ff6b11;
					font-size: 32rpx;

					display: flex;
					align-items: center;
					justify-content: center;

					height: 64rpx;
					border-radius: 8rpx;
					border: 2rpx dashed #ff6b11;

					image {
						width: 36rpx;
						height: 36rpx;
						margin-right: 8rpx;
					}
				}
			}

			&-item {
				padding: 0 28rpx;
				height: 100rpx;
				display: flex;
				align-items: center;
				border-top: 2rpx solid #fafafa;

				&-left {
					color: #333;
					width: 146rpx;
					font-size: 28rpx;
				}

				&-right {
					flex: 1;
					position: relative;
					padding-left: 24rpx;
					display: flex;
					align-items: center;

					input {
						flex: 1;
						color: #000;
						height: 100rpx;
						line-height: 100rpx;
						padding: 0 50rpx 0 0rpx;
						border-radius: 16rpx;
					}

					image {
						position: absolute;
						top: 30rpx;
						right: 0;
						width: 32rpx;
						height: 32rpx;
						z-index: 999;
					}
					&-tips {
						flex-shrink: 0;

						&.weights {
							position: static;
							width: 80rpx;
							height: 32rpx;
							margin-right: 16rpx;
						}
					}

					/deep/ .placeholder {
						color: #666;
						font-size: 26rpx;
					}
				}

				&:first-child {
					border: none;
				}
			}

			&.protocol {
				margin-top: 20rpx;
				padding: 0 28rpx;

				height: 146rpx;
				display: flex;
				align-items: center;

				.protocol-left {
					flex: 1;
					color: #666;
					font-size: 24rpx;

					view:first-child {
						color: #000;
						font-size: 28rpx;
						font-weight: bold;
						margin-bottom: 12rpx;
					}
				}

				.protocol-right {
					width: 70rpx;
					display: flex;
					align-items: center;

					image {
						width: 52rpx;
						height: 52rpx;
					}
				}
			}
		}
	}

	&-footer {
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		z-index: 999;
		background: #fff;
		box-shadow: 0px 0px 8rpx 0px rgba(51, 51, 51, 0.14);

		padding: 16rpx 28rpx;
		@include Db_iosBottomDistance(16rpx);

		button {
			z-index: 999;
			@include Db_newButton(88rpx, 24rpx);
			// background: rgba(255, 107, 17, 1);

			// &:active {
			// 	background: rgba(255, 107, 17, 0.7);
			// }
		}
	}
}
</style>
